package com.test09_抽象类和接口;

import org.junit.Test;

/**
 * 抽象类
 */
public class YootkDemo_01 {

    @Test
    public void test1() {
         // Book book = new Book();    // 抽象类不能实例化
        Book book = new MathBook();
        book.read();
    }

    @Test
    public void test2() {
        Book book = new MathBook("线性代数", "小陈老师", 59.8, "高级数学");
        System.out.println(book);
    }

    @Test
    public void test3() {
        // 调用抽象类的static方法
        Book book = Book.getBook();
        book.read();
    }
}

abstract class Book {   // 抽象类
    private String title;
    private String author;
    private double price;

    public Book() {
    }

    public Book(String title, String author, double price) {
        this.title = title;
        this.author = author;
        this.price = price;
    }

    public abstract void read();    // 抽象方法，没有方法体

    public static Book getBook() {  // 抽象类定义static方法
        return new MathBook();
    }

    @Override
    public String toString() {
        return "【Book】图书名称：" + this.title + "、图书作者：" + this.author + "、图书价格：" + this.price;
    }
}

class MathBook extends Book {   // 普通类
    private String type;

    public MathBook() {
    }

    public MathBook(String title, String author, double price, String type) {
        super(title, author, price);
        this.type = type;
    }

    @Override
    public void read() {
        System.out.println("【MathBook】开始阅读数学类的图书");
    }

    @Override
    public String toString() {
        return super.toString() + "、分类：" + this.type;
    }
}
